﻿using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using EnvDTE80;
using Microsoft.VisualStudio.Shell;

namespace theeg.DependencyAnalysis.VsAddin
{
    [Guid("63f1ab28-4c98-4f66-9251-1fe8017eab4e")]
    public class EggAndGherkinToolWindow : ToolWindowPane
    {
        public static DTE2 ApplicationDte;

        public EggAndGherkinToolWindow() :
            base(null)
        {
            Caption = Resources.ToolWindowTitle;
            BitmapResourceID = 301;
            BitmapIndex = 1;

            base.Content = CreateToolWindow(ApplicationDte);
        }

        private object CreateToolWindow(DTE2 applicationDte)
        {
            var location = GetType().Assembly.Location;
            var directoryName = Path.GetDirectoryName(location);
            var vsAddin = Assembly.LoadFile(directoryName + "\\theeg.DependencyAnalysis.VsAddin2012.dll");
            var connect = vsAddin.GetType("theeg.DependencyAnalysis.VsAddin2012.Connect");
            var methodInfo = connect.GetMethod("CreateToolWindow");
            var result = methodInfo.Invoke(null, new object[] {applicationDte});
            return result;
        }
    }
}
